import coin.exchange.base.kr_rest.native_public_client_base as npubcb
from coin.exchange.huobi_futures.kr_rest.futures_constants import native_subscription_symbol_list


class HuobiFuturesNativePublicClient(npubcb.NativePublicClientBase):
  def __init__(self, timeout=3):
    npubcb.NativePublicClientBase.__init__(self, url="https://api.hbdm.com", timeout=timeout)
    self._valid_symbol_type = native_subscription_symbol_list
    self._valid_kline_period = ['1min', '5min', '15min', '30min', '60min', \
      '4hour', '1day', '1mon']

  def check_symbol(self, symbol):
    assert symbol in self._valid_symbol_type, \
        'Invalid contract type!'

  def check_kline_period(self, kline_period):
    assert kline_period in self._valid_kline_period, \
        'Invalid kline period!'

  def get_ticker(self, symbol):
    self.check_symbol(symbol)
    url = 'market/detail/merged'
    params = {'symbol': symbol}
    update = self._get_as_json(url, params)
    return update

  def get_orderbook(self, symbol, contract_type, size=5, merge=1):
    raise NotImplementedError()

  def get_history_kline(self, symbol, kline_period, size):
    self.check_kline_period(kline_period)
    url = "market/history/kline"
    params = {
        'symbol': symbol,
        'period': kline_period,
        'size': size,
    }
    update = self._get_as_json(url, params)
    return update

  def queryAll(self):
    raise NotImplementedError()


if __name__ == "__main__":
  client = HuobiFuturesNativePublicClient()
  print(client.get_history_kline('BTC_CW', '60min', 10))
  print(client.get_ticker('BTC_CW'))
